# LuckPay Web Manage System
#
# Copyright (c) 2016 Lucky Byte, Inc.
#
$ ->
    $('form#message').hide()

    $("#end_time").keypress (evt) ->
        $('form#date_form').submit()

    $('a#user_filter').click (evt) ->
        evt.preventDefault()
        form = $('form#date_form')
        form.form 'set value', 'user', $(this).data('user')
        form.submit()

    $('a#message_read').click (evt) ->
        evt.preventDefault()
        $.post '/message/read', {
            serial: $(this).data('serial'),
            recver: $(this).data('recver'),
        }, (resp) ->
            if resp.succ
                window.location =
                    "/message?user=#{$('form#date_form').form 'get value', 'user'}"

    $('a#delete').click (evt) ->
        evt.preventDefault()
        $.post '/message/delete', {
            serial: $(this).data('serial'),
        }, (resp) ->
            if resp.succ
                window.location =
                    "/message?user=#{$('form#date_form').form 'get value', 'user'}"

    $('a#reply').click (evt) ->
        evt.preventDefault()
        if $(this).hasClass('has_clicked')
            $(this).parent().next('form#message').hide('fast')
            $(this).removeClass('has_clicked')
        else
            $(this).parent().next('form#message').show('fast')
            $(this).addClass('has_clicked')

    $('button#clear').click (evt) ->
        $('form#date_form').form 'set values',
            'start_time': '', 'end_time': ''
